package cn.dinxian.activiti.demo2.tool;

import cn.dinxian.entity.PageDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import org.activiti.engine.query.Query;
public class PageUtils {

	public static <T> IPage<T> getPage(Query query, PageDTO pageDTO) {
		long count = query.count();
		List list = query.listPage(((pageDTO.getCurrent() - 1) * pageDTO.getPageSize()), pageDTO.getPageSize());
		Page page = new Page();
		page.setRecords(list);
		page.setCurrent(pageDTO.getCurrent());
		page.setSize(pageDTO.getPageSize());
		page.setTotal(count);
		page.setPages((long) Math.ceil((count + 0.0) / pageDTO.getPageSize()));
		return page;
	}

}
